package cn.edu.nuc.ssm.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.edu.nuc.ssm.domain.Film;
import cn.edu.nuc.ssm.domain.Sysuser;
import cn.edu.nuc.ssm.service.interfaces.FilmService;

/**
 * 后台登录成功索引页。。。。
 */
@Controller
public class IndexPageController {
	@Autowired
	private FilmService filmServiceImpl;
//	@RequestMapping("index2")
//	public String index2() {
//		return "sys/index2";
//	}

	// 获得全部的3个模块的电影
	@RequestMapping(value = "index", method = RequestMethod.GET)
	public String selectByHot(Model model) {
		List<List<Film>> list = filmServiceImpl.select2();
		if (list.size() > 0) {
			model.addAttribute("list", list);
			return "forward:/index.jsp";
		}
		return "error";
	}
	
	//详情页面的购票按钮。
	@RequestMapping(value = "buy/{filmid}", method = RequestMethod.GET)
	public String buy(HttpServletRequest req,@PathVariable("filmid") int filmid,Model model){
		HttpSession session = req.getSession();
		Sysuser user = (Sysuser) session.getAttribute("user");
		Film film = filmServiceImpl.selectByFilmid(filmid);
		if(user != null && user.getUsername()!=null){
		   model.addAttribute("id", filmid);
		   model.addAttribute("kucun", film.getTicket());
		   return "forward:/select.jsp";
		}
		return "forward:/login.jsp";
	}
}
